﻿$(document).ready(function () {
    var toNis = false;
    $.get("../Convert.aspx?get=amount", function (answer) {
        document.getElementById("amount").innerHTML = answer;
    });
    var toUsd = false;
    $("#convertBtn").click(function () {
        var from = document.getElementById("selectFrom").value;
        var to = document.getElementById("selectTo").value;
        if ((to == "nis" && from == "nis") || (to == "usd" && from == "usd")) {
            return;
        }
        if (to == "nis" && toNis == false) {
            toNis = true;
            toUsd = false;
            var amount = document.getElementById("amount").innerHTML;
            var qry = "?from=" + from + "&to=" + to + "&amount=" + amount;
            $.get("../Convert.aspx" + qry, function (answer) {
                document.getElementById("amount").innerHTML = answer;
            });
        }
        else if (to == "usd" && toUsd == false) {
            toUsd = true;
            toNis = false;
            var amount = document.getElementById("amount").innerHTML;
            var qry = "?from=" + from + "&to=" + to + "&amount=" + amount;
            $.get("../Convert.aspx" + qry, function (answer) {
                document.getElementById("amount").innerHTML = answer;
            });
        }
        else {
            return;
        }
    });
});